using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace CXDB
{
	/// <summary>
	/// Strongly-typed collection for the CxApply class.
	/// </summary>
    [Serializable]
	public partial class CxApplyCollection : ActiveList<CxApply, CxApplyCollection>
	{	   
		public CxApplyCollection() {}
        
        /// <summary>
		/// Filters an existing collection based on the set criteria. This is an in-memory filter
		/// Thanks to developingchris for this!
        /// </summary>
        /// <returns>CxApplyCollection</returns>
		public CxApplyCollection Filter()
        {
            for (int i = this.Count - 1; i > -1; i--)
            {
                CxApply o = this[i];
                foreach (SubSonic.Where w in this.wheres)
                {
                    bool remove = false;
                    System.Reflection.PropertyInfo pi = o.GetType().GetProperty(w.ColumnName);
                    if (pi.CanRead)
                    {
                        object val = pi.GetValue(o, null);
                        switch (w.Comparison)
                        {
                            case SubSonic.Comparison.Equals:
                                if (!val.Equals(w.ParameterValue))
                                {
                                    remove = true;
                                }
                                break;
                        }
                    }
                    if (remove)
                    {
                        this.Remove(o);
                        break;
                    }
                }
            }
            return this;
        }
		
		
	}
	/// <summary>
	/// This is an ActiveRecord class which wraps the CX_Apply table.
	/// </summary>
	[Serializable]
	public partial class CxApply : ActiveRecord<CxApply>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public CxApply()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}
		
		private void InitSetDefaults() { SetDefaults(); }
		
		public CxApply(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}
        
		public CxApply(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}
		 
		public CxApply(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}
		
		protected static void SetSQLProps() { GetTableSchema(); }
		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}
		}
		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("CX_Apply", TableType.Table, DataService.GetInstance("CXDB"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarId = new TableSchema.TableColumn(schema);
				colvarId.ColumnName = "ID";
				colvarId.DataType = DbType.Int32;
				colvarId.MaxLength = 0;
				colvarId.AutoIncrement = true;
				colvarId.IsNullable = false;
				colvarId.IsPrimaryKey = true;
				colvarId.IsForeignKey = false;
				colvarId.IsReadOnly = false;
				colvarId.DefaultSetting = @"";
				colvarId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarId);
				
				TableSchema.TableColumn colvarUid = new TableSchema.TableColumn(schema);
				colvarUid.ColumnName = "uid";
				colvarUid.DataType = DbType.Int32;
				colvarUid.MaxLength = 0;
				colvarUid.AutoIncrement = false;
				colvarUid.IsNullable = true;
				colvarUid.IsPrimaryKey = false;
				colvarUid.IsForeignKey = false;
				colvarUid.IsReadOnly = false;
				colvarUid.DefaultSetting = @"";
				colvarUid.ForeignKeyTableName = "";
				schema.Columns.Add(colvarUid);
				
				TableSchema.TableColumn colvarGuid = new TableSchema.TableColumn(schema);
				colvarGuid.ColumnName = "Guid";
				colvarGuid.DataType = DbType.Guid;
				colvarGuid.MaxLength = 0;
				colvarGuid.AutoIncrement = false;
				colvarGuid.IsNullable = true;
				colvarGuid.IsPrimaryKey = false;
				colvarGuid.IsForeignKey = false;
				colvarGuid.IsReadOnly = false;
				colvarGuid.DefaultSetting = @"";
				colvarGuid.ForeignKeyTableName = "";
				schema.Columns.Add(colvarGuid);
				
				TableSchema.TableColumn colvarReason = new TableSchema.TableColumn(schema);
				colvarReason.ColumnName = "Reason";
				colvarReason.DataType = DbType.String;
				colvarReason.MaxLength = 500;
				colvarReason.AutoIncrement = false;
				colvarReason.IsNullable = true;
				colvarReason.IsPrimaryKey = false;
				colvarReason.IsForeignKey = false;
				colvarReason.IsReadOnly = false;
				colvarReason.DefaultSetting = @"";
				colvarReason.ForeignKeyTableName = "";
				schema.Columns.Add(colvarReason);
				
				TableSchema.TableColumn colvarTbname = new TableSchema.TableColumn(schema);
				colvarTbname.ColumnName = "tbname";
				colvarTbname.DataType = DbType.String;
				colvarTbname.MaxLength = 50;
				colvarTbname.AutoIncrement = false;
				colvarTbname.IsNullable = true;
				colvarTbname.IsPrimaryKey = false;
				colvarTbname.IsForeignKey = false;
				colvarTbname.IsReadOnly = false;
				colvarTbname.DefaultSetting = @"";
				colvarTbname.ForeignKeyTableName = "";
				schema.Columns.Add(colvarTbname);
				
				TableSchema.TableColumn colvarCountTimes = new TableSchema.TableColumn(schema);
				colvarCountTimes.ColumnName = "CountTimes";
				colvarCountTimes.DataType = DbType.Int32;
				colvarCountTimes.MaxLength = 0;
				colvarCountTimes.AutoIncrement = false;
				colvarCountTimes.IsNullable = true;
				colvarCountTimes.IsPrimaryKey = false;
				colvarCountTimes.IsForeignKey = false;
				colvarCountTimes.IsReadOnly = false;
				colvarCountTimes.DefaultSetting = @"";
				colvarCountTimes.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCountTimes);
				
				TableSchema.TableColumn colvarStatus = new TableSchema.TableColumn(schema);
				colvarStatus.ColumnName = "Status";
				colvarStatus.DataType = DbType.Int32;
				colvarStatus.MaxLength = 0;
				colvarStatus.AutoIncrement = false;
				colvarStatus.IsNullable = true;
				colvarStatus.IsPrimaryKey = false;
				colvarStatus.IsForeignKey = false;
				colvarStatus.IsReadOnly = false;
				colvarStatus.DefaultSetting = @"";
				colvarStatus.ForeignKeyTableName = "";
				schema.Columns.Add(colvarStatus);
				
				TableSchema.TableColumn colvarInTime = new TableSchema.TableColumn(schema);
				colvarInTime.ColumnName = "inTime";
				colvarInTime.DataType = DbType.DateTime;
				colvarInTime.MaxLength = 0;
				colvarInTime.AutoIncrement = false;
				colvarInTime.IsNullable = true;
				colvarInTime.IsPrimaryKey = false;
				colvarInTime.IsForeignKey = false;
				colvarInTime.IsReadOnly = false;
				
						colvarInTime.DefaultSetting = @"(getdate())";
				colvarInTime.ForeignKeyTableName = "";
				schema.Columns.Add(colvarInTime);
				
				TableSchema.TableColumn colvarBossID = new TableSchema.TableColumn(schema);
				colvarBossID.ColumnName = "BossID";
				colvarBossID.DataType = DbType.Int32;
				colvarBossID.MaxLength = 0;
				colvarBossID.AutoIncrement = false;
				colvarBossID.IsNullable = true;
				colvarBossID.IsPrimaryKey = false;
				colvarBossID.IsForeignKey = false;
				colvarBossID.IsReadOnly = false;
				colvarBossID.DefaultSetting = @"";
				colvarBossID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarBossID);
				
				TableSchema.TableColumn colvarBossNod = new TableSchema.TableColumn(schema);
				colvarBossNod.ColumnName = "BossNod";
				colvarBossNod.DataType = DbType.Int32;
				colvarBossNod.MaxLength = 0;
				colvarBossNod.AutoIncrement = false;
				colvarBossNod.IsNullable = true;
				colvarBossNod.IsPrimaryKey = false;
				colvarBossNod.IsForeignKey = false;
				colvarBossNod.IsReadOnly = false;
				colvarBossNod.DefaultSetting = @"";
				colvarBossNod.ForeignKeyTableName = "";
				schema.Columns.Add(colvarBossNod);
				
				TableSchema.TableColumn colvarBossTime = new TableSchema.TableColumn(schema);
				colvarBossTime.ColumnName = "BossTime";
				colvarBossTime.DataType = DbType.DateTime;
				colvarBossTime.MaxLength = 0;
				colvarBossTime.AutoIncrement = false;
				colvarBossTime.IsNullable = true;
				colvarBossTime.IsPrimaryKey = false;
				colvarBossTime.IsForeignKey = false;
				colvarBossTime.IsReadOnly = false;
				colvarBossTime.DefaultSetting = @"";
				colvarBossTime.ForeignKeyTableName = "";
				schema.Columns.Add(colvarBossTime);
				
				TableSchema.TableColumn colvarUserTime = new TableSchema.TableColumn(schema);
				colvarUserTime.ColumnName = "userTime";
				colvarUserTime.DataType = DbType.DateTime;
				colvarUserTime.MaxLength = 0;
				colvarUserTime.AutoIncrement = false;
				colvarUserTime.IsNullable = true;
				colvarUserTime.IsPrimaryKey = false;
				colvarUserTime.IsForeignKey = false;
				colvarUserTime.IsReadOnly = false;
				colvarUserTime.DefaultSetting = @"";
				colvarUserTime.ForeignKeyTableName = "";
				schema.Columns.Add(colvarUserTime);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["CXDB"].AddSchema("CX_Apply",schema);
			}
		}
		#endregion
		
		#region Props
		  
		[XmlAttribute("Id")]
		[Bindable(true)]
		public int Id 
		{
			get { return GetColumnValue<int>(Columns.Id); }
			set { SetColumnValue(Columns.Id, value); }
		}
		  
		[XmlAttribute("Uid")]
		[Bindable(true)]
		public int? Uid 
		{
			get { return GetColumnValue<int?>(Columns.Uid); }
			set { SetColumnValue(Columns.Uid, value); }
		}
		  
		[XmlAttribute("Guid")]
		[Bindable(true)]
		public Guid? Guid 
		{
			get { return GetColumnValue<Guid?>(Columns.Guid); }
			set { SetColumnValue(Columns.Guid, value); }
		}
		  
		[XmlAttribute("Reason")]
		[Bindable(true)]
		public string Reason 
		{
			get { return GetColumnValue<string>(Columns.Reason); }
			set { SetColumnValue(Columns.Reason, value); }
		}
		  
		[XmlAttribute("Tbname")]
		[Bindable(true)]
		public string Tbname 
		{
			get { return GetColumnValue<string>(Columns.Tbname); }
			set { SetColumnValue(Columns.Tbname, value); }
		}
		  
		[XmlAttribute("CountTimes")]
		[Bindable(true)]
		public int? CountTimes 
		{
			get { return GetColumnValue<int?>(Columns.CountTimes); }
			set { SetColumnValue(Columns.CountTimes, value); }
		}
		  
		[XmlAttribute("Status")]
		[Bindable(true)]
		public int? Status 
		{
			get { return GetColumnValue<int?>(Columns.Status); }
			set { SetColumnValue(Columns.Status, value); }
		}
		  
		[XmlAttribute("InTime")]
		[Bindable(true)]
		public DateTime? InTime 
		{
			get { return GetColumnValue<DateTime?>(Columns.InTime); }
			set { SetColumnValue(Columns.InTime, value); }
		}
		  
		[XmlAttribute("BossID")]
		[Bindable(true)]
		public int? BossID 
		{
			get { return GetColumnValue<int?>(Columns.BossID); }
			set { SetColumnValue(Columns.BossID, value); }
		}
		  
		[XmlAttribute("BossNod")]
		[Bindable(true)]
		public int? BossNod 
		{
			get { return GetColumnValue<int?>(Columns.BossNod); }
			set { SetColumnValue(Columns.BossNod, value); }
		}
		  
		[XmlAttribute("BossTime")]
		[Bindable(true)]
		public DateTime? BossTime 
		{
			get { return GetColumnValue<DateTime?>(Columns.BossTime); }
			set { SetColumnValue(Columns.BossTime, value); }
		}
		  
		[XmlAttribute("UserTime")]
		[Bindable(true)]
		public DateTime? UserTime 
		{
			get { return GetColumnValue<DateTime?>(Columns.UserTime); }
			set { SetColumnValue(Columns.UserTime, value); }
		}
		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(int? varUid,Guid? varGuid,string varReason,string varTbname,int? varCountTimes,int? varStatus,DateTime? varInTime,int? varBossID,int? varBossNod,DateTime? varBossTime,DateTime? varUserTime)
		{
			CxApply item = new CxApply();
			
			item.Uid = varUid;
			
			item.Guid = varGuid;
			
			item.Reason = varReason;
			
			item.Tbname = varTbname;
			
			item.CountTimes = varCountTimes;
			
			item.Status = varStatus;
			
			item.InTime = varInTime;
			
			item.BossID = varBossID;
			
			item.BossNod = varBossNod;
			
			item.BossTime = varBossTime;
			
			item.UserTime = varUserTime;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varId,int? varUid,Guid? varGuid,string varReason,string varTbname,int? varCountTimes,int? varStatus,DateTime? varInTime,int? varBossID,int? varBossNod,DateTime? varBossTime,DateTime? varUserTime)
		{
			CxApply item = new CxApply();
			
				item.Id = varId;
			
				item.Uid = varUid;
			
				item.Guid = varGuid;
			
				item.Reason = varReason;
			
				item.Tbname = varTbname;
			
				item.CountTimes = varCountTimes;
			
				item.Status = varStatus;
			
				item.InTime = varInTime;
			
				item.BossID = varBossID;
			
				item.BossNod = varBossNod;
			
				item.BossTime = varBossTime;
			
				item.UserTime = varUserTime;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn IdColumn
        {
            get { return Schema.Columns[0]; }
        }
        
        
        
        public static TableSchema.TableColumn UidColumn
        {
            get { return Schema.Columns[1]; }
        }
        
        
        
        public static TableSchema.TableColumn GuidColumn
        {
            get { return Schema.Columns[2]; }
        }
        
        
        
        public static TableSchema.TableColumn ReasonColumn
        {
            get { return Schema.Columns[3]; }
        }
        
        
        
        public static TableSchema.TableColumn TbnameColumn
        {
            get { return Schema.Columns[4]; }
        }
        
        
        
        public static TableSchema.TableColumn CountTimesColumn
        {
            get { return Schema.Columns[5]; }
        }
        
        
        
        public static TableSchema.TableColumn StatusColumn
        {
            get { return Schema.Columns[6]; }
        }
        
        
        
        public static TableSchema.TableColumn InTimeColumn
        {
            get { return Schema.Columns[7]; }
        }
        
        
        
        public static TableSchema.TableColumn BossIDColumn
        {
            get { return Schema.Columns[8]; }
        }
        
        
        
        public static TableSchema.TableColumn BossNodColumn
        {
            get { return Schema.Columns[9]; }
        }
        
        
        
        public static TableSchema.TableColumn BossTimeColumn
        {
            get { return Schema.Columns[10]; }
        }
        
        
        
        public static TableSchema.TableColumn UserTimeColumn
        {
            get { return Schema.Columns[11]; }
        }
        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string Id = @"ID";
			 public static string Uid = @"uid";
			 public static string Guid = @"Guid";
			 public static string Reason = @"Reason";
			 public static string Tbname = @"tbname";
			 public static string CountTimes = @"CountTimes";
			 public static string Status = @"Status";
			 public static string InTime = @"inTime";
			 public static string BossID = @"BossID";
			 public static string BossNod = @"BossNod";
			 public static string BossTime = @"BossTime";
			 public static string UserTime = @"userTime";
						
		}
		#endregion
		
		#region Update PK Collections
		
        #endregion
    
        #region Deep Save
		
        #endregion
	}
}
